var LRUCache = function (capacity) {
  this.capacity = capacity
  const map = new Map()
  this.map = map
};

/** 
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function (key) {
  if (this.map.has(key)) {
    let value = this.map.get(key);
    this.map.delete(key);
    this.map.set(key, value);
    return value
  } else {
    return -1
  }
};

/** 
 * @param {number} key 
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function (key, value) {
  if (this.map.has(key)) {
    this.map.delete(key);
  }
  this.map.set(key, value);
  if (this.map.size > this.capacity) {
    this.map.delete(this.map.keys().next().value);
  }
};

const lRUCache = new LRUCache(2);
lRUCache.put(1, 1)
lRUCache.put(2, 2)
lRUCache.get(1);
lRUCache.put(3, 3);
console.log(lRUCache.get(2));